package com.jycode.commons.genericdao.finder.impl;

import com.jycode.commons.genericdao.finder.FinderArgumentTypeFactory;

/**
 * Maps Enums to a custom Hibernate user type
 */
public class SimpleFinderArgumentTypeFactory implements FinderArgumentTypeFactory
{
    public org.hibernate.type.Type getArgumentType(Object arg)
    {
        if(arg instanceof Enum)
        {
            return getEnumType(arg.getClass());
        }
        else
        {
            return null;
        }
    }

    private org.hibernate.type.Type getEnumType(Class<? extends Object> argClass)
    {
        java.util.Properties p = new java.util.Properties();
        p.setProperty("enumClassName", argClass.getName());
        org.hibernate.type.Type enumType = org.hibernate.type.TypeFactory.heuristicType("org.hibernate.demo.EnumUserType", p);
        return enumType;
    }
}
